<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Group extends AppModel {
    
    ////////////////////////
    public $hasMany = array (        
        'Action'=>array (
            'foreignKey' => 'groups_id'
        ),         
        'ActionsComment'=>array (
            'foreignKey' => 'groups_id'
        ),       
        'ImplementedLawGroup'=>array (
            'foreignKey' => 'groups_id'
        ),        
        'UserGroup' => array(
            'foreignKey' => 'groups_id',
        ),
        'GroupsNotification' => array(
            'foreignKey' => 'groups_id',
        ),
    );
    
    ////////////////////////
    public $belongsTo = array (
        'PlaceCity'=>array (
            'foreignKey' => 'cities_id'
        )
    );
    
    
     var $validate = array(
        'name' => array(
            'between' => array(
                'rule' => array('between', 3, 255),
                'message' => 'Nom du groupe doit être compris entre 3 et 255 caractères'
            ))
        );
    
     
     public function countUsers($id){
         $data =$this->UserGroup->find('count', array(
             'conditions' => array(
                 'UserGroup.groups_id' => $id
             ),
         ));
         return $data;
     }
     
     public function getGroup($type, $options){
         $data = $this->find($type, $options);
         return $data;
     }
}

?>
